package erQiao.yfl.app.controller;

import erQiao.yfl.app.common.Result;
import erQiao.yfl.app.controller.Vo.CircleVo;
import erQiao.yfl.app.controller.Vo.PrescriptionVo;
import erQiao.yfl.app.dao.entity.Circle;
import erQiao.yfl.app.dao.entity.Prescription;
import erQiao.yfl.app.dao.mapper.PrescriptionMapper;
import erQiao.yfl.app.service.CommentService;
import erQiao.yfl.app.service.PrescriptionService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 偏方表
 */
@Controller
@RequestMapping("/prescription")
public class PrescriptionController {
    @Resource
    private PrescriptionService prescriptionService;
    @Resource
    private CommentService commentService;

    @RequestMapping("/selectCircleById")
    public Result selectCircleById(HttpServletRequest request){
        int id = Integer.valueOf(request.getParameter("id"));
        return Result.wrapSuccessResult(prescriptionService.selectByPrimaryKey(id));
    }

    @RequestMapping("/delCircleById")
    public void delCircleById(HttpServletRequest request){
        int id = Integer.valueOf(request.getParameter("id"));
        prescriptionService.delPrescriptionById(id);
    }

    /**
     * 修改
     *  @param prescriptionVo
     */
    @RequestMapping("/updateByPrimaryKey")
    public void updateByPrimaryKey(@RequestBody PrescriptionVo prescriptionVo){
        Prescription prescription = new Prescription();
        BeanUtils.copyProperties(prescriptionVo,prescription);
        prescriptionService.updateByPrimaryKey(prescription);
    }


    /**
     * 新增
     * @param PrescriptionVo
     */
    @RequestMapping("/insertCircle")
    public void insertCircle(@RequestBody PrescriptionVo prescriptionVo){
        Prescription prescription = new Prescription();
        BeanUtils.copyProperties(prescriptionVo,prescription);
        prescriptionService.insertPrescription(prescription);
    }


}
